package com.cl.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cl.utils.DBUtils;

/**
 * @author cl
 * @explain JS= Job Seeker
 * 
 * */
@Controller
public class JSLoginAndSignController {

	@Autowired
	private SessionFactory sf;
	
	@RequestMapping("jsLogin")
	private String jsLogin(String jsName,String jsPwd) {
		List<Map<String,Object>> retList = new ArrayList<Map<String,Object>>();
		retList = DBUtils.queryForList("select * from user where name= '"+jsName+"' and pwd = '"+jsPwd+"' and type = 1");
		System.out.println(retList.toString());
		
		return  retList.size()>0?"1":"0";
	}
	
	
	
	/**
	 * 后台不做insert返回检查 insert前验证
	 * 
	 * */
	@RequestMapping("jsSign")
	private String jsSign(String jsName,String jsPwd) {
		
		List<Map<String,Object>> retList = new ArrayList<Map<String,Object>>();
		try {
			//验证用户名是否存在 存在直接返回错误
			retList = DBUtils.queryForList("select * from user where name= '"+jsName+"' and type = 1");
			
			if(retList.size()<0)
				DBUtils.insert("insert into user values('"+jsName+"','"+jsPwd+"',1)");
			else 
				System.out.println(retList.toString());
				return "0";
			
				
		} catch (SQLException e) {
			
			e.printStackTrace();
		}finally {
		//	return "12";
		}
		return "1";
	}
	
	
}
